import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:lazy_food/models/degrease_model.dart';
import 'package:lazy_food/models/follow_model.dart';
import 'package:lazy_food/models/recommend_model.dart';
import 'package:lazy_food/models/tab_model.dart';
import 'package:lazy_food/models/vip_model.dart';
import 'package:lazy_food/models/weekly_model.dart';

import '../models/tag_model.dart';

class Network {
  static String _baseUrl = "https://gitee.com/liyb93/lazy_food/raw/master/api";

  // 首页推荐
  static Future<RecommendModel> getHomeRecommend() async {
    String url = _baseUrl + "/home_rcmd.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    RecommendModel model = RecommendModel.fromJson(response.data);
    return model;
  }

  // 首页tabs
  static Future<List<TabModel>> getHomeTabs() async {
    String url = _baseUrl + "/home_tabs.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<TabModel> models = data.map((e) {
      return TabModel.fromJson(e);
    }).toList();
    return models;
  }

  // 减脂
  static Future<List<DegreaseModel>> getDegrease() async {
    String url = _baseUrl + "/degrease_all.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<DegreaseModel> models = data.map((e) {
      return DegreaseModel.fromJson(e);
    }).toList();
    return models;
  }

  // 减脂tabs
  static Future<List<TabModel>> getDegreaseTabs() async {
    String url = _baseUrl + "/degrease_tabs.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<TabModel> models = data.map((e) {
      return TabModel.fromJson(e);
    }).toList();
    return models;
  }

  // 首页其他
  static Future<List<RecommendFoodModel>> getHomeOther(TabModel tab) async {
    String url = _baseUrl + "/home_${tab.ident}.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<RecommendFoodModel> models = data.map((e) {
      return RecommendFoodModel.fromJson(e);
    }).toList();
    return models;
  }

  // 首页关注
  static Future<List<FollowModel>> getHomeFollow() async {
    String url = _baseUrl + "/home_follow.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<FollowModel> models = data.map((e) {
      return FollowModel.fromJson(e);
    }).toList();
    return models;
  }

  // 首页vip 
  static Future<List<VipModel>> getHomeVip() async {
    String url = _baseUrl + "/home_vip.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<VipModel> models = data.map((e) {
      return VipModel.fromJson(e);
    }).toList();
    return models;
  }

  // 首页每周
  static Future<List<WeeklyModel>> getHomeWeekly() async {
    String url = _baseUrl + "/home_weekly.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<WeeklyModel> models = data.map((e) {
      return WeeklyModel.fromJson(e);
    }).toList();
    return models;
  }

  // 首页排行榜
  static Future<List<VipModel>> getHomeRank() async {
    String url = _baseUrl + "/home_rank.json";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<VipModel> models = data.map((e) {
      return VipModel.fromJson(e);
    }).toList();
    return models;
  }

  // 搜索tag
  static Future<List<TagModel>> getSearchTags() async {
    String url = _baseUrl = "";
    Response response =
        await Dio().get(url, options: Options(responseType: ResponseType.json));
    List<dynamic> data = response.data;
    List<TagModel> models = data.map((e) {
      return TagModel.fromJson(e);
    }).toList();
    return models;
  }
}
